﻿using System;
using System.Collections;

namespace Quail.Silverlight
{
    /// <summary>
    /// Wraps the silverlight datagrid controls
    /// </summary>
    public class SlvDataGrid : SlvControl, ISlvControlWithRows
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="SlvDataGrid"/> class.
        /// </summary>
        public SlvDataGrid()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SlvDataGrid"/> class.
        /// </summary>
        /// <param name="container">The container for the control.</param>
        /// <param name="selector">The selector.</param>
        public SlvDataGrid(SlvControlContainer container, string selector)
            : base(container, selector)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SlvDataGrid"/> class.
        /// </summary>
        /// <param name="control">The control.</param>
        public SlvDataGrid(SlvControl control)
            : base(control)
        {
        }

        /// <summary>
        /// Gets the number of rows in the datagrid
        /// </summary>
        public int RowCount
        {
            get { return int.Parse(GetPropertyValue("RowCount")); }
        }

        /// <summary>
        /// Gets the number of columns in the datagrid
        /// </summary>
        public int ColumnCount
        {
            get { return int.Parse(GetPropertyValue("ColumnCount")); }
        }

        /// <summary>
        /// Gets or sets the currently selected row
        /// </summary>
        public int FocusedRow
        {
            get
            {
                return int.Parse(GetPropertyValue("SelectedRow"));
            }

            set
            {
                SetPropertyValue("SelectedRow", value.ToString());
                Browser.Sleep(500);
            }
        }

        /// <summary>
        /// Gets or sets the currently selected column
        /// </summary>
        public int FocusedColumn
        {
            get
            {
                return int.Parse(GetPropertyValue("SelectedColumn"));
            }

            set
            {
                SetPropertyValue("SelectedColumn", value.ToString());
                Browser.Sleep(500);
            }
        }

        /// <summary>
        /// Gets a hashtable for the controls
        /// </summary>
        public Hashtable ControlHashtable
        {
            get
            {
                return HashControls;
            }
        }

        /// <summary>
        /// Gets the value from a give row/column
        /// </summary>
        /// <param name="row">the row to check</param>
        /// <param name="column">the column</param>
        /// <returns>the string value</returns>
        public string GetRowColumnValue(int row, int column)
        {
            return CallMethod("GetRowColumnValue", row.ToString(), column.ToString());
        }
    }
}
